﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Business.IManager;
using Business.Manager;
using Entity;
using System.Data;
using System.Collections;
namespace OnlinePayment.Admin
{
    public partial class InsertNewStudent : System.Web.UI.Page
    {
        IAccountManager accountManager = new AccountManager();
        IAcademyManager academyManager = new AcademyManager();
        public DataTable academyTable;
        public DataTable majorTable;
        public int year = Convert.ToInt32(DateTime.Today.Year.ToString());
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                init();
            } 
        }

        private void init()
        {
            academyTable = academyManager.getAcademyTable();
            ddlAcademy.DataSource = academyTable;
            ddlAcademy.DataTextField = "acaName";
            ddlAcademy.DataValueField = "acaId";
            ddlAcademy.DataBind();
            ddlAcademy.Items.Insert(0, new ListItem("请选择", ""));

            
            /*academyHashtable = academyManager.getAcademyHashtable();
            ddlAcademy.DataSource = academyHashtable.Keys;
            ddlAcademy.DataBind();
            ddlAcademy.Items.Insert(0, new ListItem("请选择", ""));*/

            majorTable = academyManager.getMajorTable();

            ddlFirstMajor.DataSource = majorTable;
            ddlFirstMajor.DataTextField = "majName";
            ddlFirstMajor.DataValueField = "majId";
            ddlFirstMajor.DataBind();
            ddlFirstMajor.Items.Insert(0, new ListItem("请选择", ""));


            ddlSecondMajor.DataSource = majorTable;
            ddlSecondMajor.DataTextField = "majName";
            ddlSecondMajor.DataValueField = "majId";
            ddlSecondMajor.DataBind();
            ddlSecondMajor.Items.Insert(0, new ListItem("请选择", ""));

            
        }

        protected void btn_addStudent_Click(object sender, EventArgs e)
        {
            Student student = new Student();
            student.StudentId = txtStuId.Text.ToString();
            student.StudentName = txtName.Text.ToString();
            student.FirstMajor = ddlFirstMajor.SelectedItem.Value.ToString();
            student.SecondMajor = ddlSecondMajor.SelectedItem.Value.ToString();
            student.Grade = Convert.ToInt32(txtGrade.Text.ToString());
            student.ClassNum = Convert.ToInt32(txtClassNum.Text.ToString());
            student.Password = txtInitPwd.Text.ToString();
            student.Email = txtEmail.Text.ToString();

            if (accountManager.addNewStudent(student))
            {
                Response.Write("<script language=javascript>alert('学生添加成功!');location='AnnoucementList.aspx'</script>");
            }
            else
            {
                Response.Write("<script language=javascript>alert('学生添加失败！');location='javascript:history.go(-1)'</script>");
            }
        }

        protected void btn_back_Click(object sender, EventArgs e)
        {

        }

        
    }
}